package com.xky.service.impl;

import com.xky.mapper.StudentMapper;
import com.xky.pojo.Student;
import com.xky.service.StudentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentImpl implements StudentService {
    private static final Logger logger = LoggerFactory.getLogger(StudentImpl.class);

    @Autowired
    private StudentMapper studentMapper;
    /**
     * 学生信息实现类
     * @param student
     */
    @Override
    public void addStudent(Student student) {
        try {
            logger.info("准备添加学生: {}", student);
            studentMapper.addStudent(student);
            logger.info("学生添加成功");
        } catch (Exception e) {
            logger.error("添加学生时出错: {}", e.getMessage(), e);
            throw e;
        }
    }

    /**
     * 删除学生信息
     * @param ids
     */
    @Override
    public void deleteStudent(Integer ids) {
        studentMapper.deleteStudent(ids);

    }

    /**
     * 修改学生信息
     * @param student
     */
    @Override
    public void updateStudent(Student student) {
        studentMapper.updateStudent(student);
    }

    /**
     * 根据id查找学生信息
     * @param id
     * @return
     */
    @Override
    public Student selectStudent(Integer id) {
        return studentMapper.selectStudent(id);
    }

    /**
     * 查找所有学生信息
     * @return
     */
    @Override
    public List<Student> selectAllStudent() {
        return studentMapper.selectAllStudent();
    }

}
